import { Tabs, TabsProps } from "antd";
import { TAB_VALUES } from "./constant";
import styles from "./index.module.less";
import { useState } from "react";
import GoodsType from "./GoodsType";
import {
	getAfterSaleServiceList,
	getDeliveryTimeList,
	getProductCategoryList,
	updateProductCategory
} from "@/api/modules/product";
import {
	getAboutUs,
	getPrivacyAgreement,
	updateAboutUs,
	updateAfterSaleType,
	updateDeliveryTime,
	updatePrivacyAgreement
} from "@/api/modules/setting";
import RichText from "./RichText";
import InnerTest from "./InnerTest";
import CourseModality from "./CourseModality";
import {
	addModalityItem,
	deleteModalityItem,
	getCategoryList,
	getModalityList,
	updateModalityItem,
	updateOrAddCategoryItem,
	updateOrAddModalityItem
} from "@/api/modules/course";

export default () => {
	const [activeKey, setActiveKey] = useState(TAB_VALUES.commodityType);

	const items: TabsProps["items"] = [
		{
			key: TAB_VALUES.commodityType,
			label: "商品类型",
			children: (
				<GoodsType
					fieldNames={{
						id: "category_id",
						label: "category_name",
						value: "category_id"
					}}
					keyValue={TAB_VALUES.commodityType}
					getListApi={getProductCategoryList}
					saveApi={updateProductCategory}
				/>
			)
		},
		{
			key: TAB_VALUES.aftermarketCategory,
			label: "售后类目",
			children: (
				<GoodsType
					fieldNames={{
						id: "aftersales_option_id",
						label: "aftersales_option_name",
						value: "aftersales_option_id"
					}}
					getListApi={getAfterSaleServiceList}
					saveApi={updateAfterSaleType}
				/>
			)
		},
		{
			key: TAB_VALUES.deliveryTime,
			label: "发货时效",
			children: (
				<GoodsType
					fieldNames={{
						id: "timelines_id",
						label: "timelines_name",
						value: "timelines_id"
					}}
					getListApi={getDeliveryTimeList}
					saveApi={updateDeliveryTime}
				/>
			)
		},
		{
			key: TAB_VALUES.courseModality,
			label: "课程形式",
			children: (
				<CourseModality
					fieldNames={{
						id: "base_course_category_id",
						label: "base_course_category_name",
						value: "base_course_category_id"
					}}
					getListApi={getModalityList}
					saveApi={updateOrAddModalityItem}
					deleteApi={deleteModalityItem}
				/>
			)
		},
		{
			key: TAB_VALUES.courseCategory,
			label: "课程类别",
			children: (
				<CourseModality
					fieldNames={{
						id: "course_menus_id",
						label: "course_menus_name",
						value: "course_menus_id"
					}}
					getListApi={getCategoryList}
					saveApi={updateOrAddCategoryItem}
				/>
			)
		},
		{
			key: TAB_VALUES.privacyPolicy,
			label: "隐私协议",
			children: <RichText name="agreement_content" getDataApi={getPrivacyAgreement} saveApi={updatePrivacyAgreement} />
		},
		{
			key: TAB_VALUES.aboutUs,
			label: "关于我们",
			children: <RichText name="about_us_content" getDataApi={getAboutUs} saveApi={updateAboutUs} />
		},
		{
			key: TAB_VALUES.innerTest,
			label: "内测管理",
			children: <InnerTest />
		}

		// {
		// 	key: TAB_VALUES.course,
		// 	label: "课程形式",
		// 	children: "Content of Tab Pane 3"
		// },
		// {
		// 	key: TAB_VALUES.courseCategory,
		// 	label: "课程类别",
		// 	children: "Content of Tab Pane 3"
		// }
	];

	return (
		<div className={styles.container}>
			<Tabs activeKey={activeKey} items={items} onChange={t => setActiveKey(t)} />
		</div>
	);
};
